﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tetris
{
    class Corner1 : Shape
    {
        public Corner1(Point first, Point second, Point third, Point fourth)
            : base(first, second, third, fourth)
        {
        }
        public override void Rotate(Func<int, int, int> IsPosFree)
        {
            switch (Pos)
            {
                case 0:
                    {
                        if (IsPosFree(_coordinates[1].x - 2, _coordinates[1].y) == 0 & IsPosFree(_coordinates[2].x - 1, _coordinates[2].y + 1) == 0 & IsPosFree(_coordinates[4].x + 1, _coordinates[4].y - 1) == 0)
                        {
                            for (int i = 0; i <= _coordinates.Count - 1; i++)
                            {
                                _lastcoordinates[i].x = _coordinates[i].x;
                                _lastcoordinates[i].y = _coordinates[i].y;
                            }
                            _coordinates[1].x = _coordinates[4].x - 2;
                            _coordinates[2].x--;
                            _coordinates[2].y++;
                            _coordinates[4].x++;
                            _coordinates[4].y--;
                            Pos = 1;
                        }
                        break;
                    }
                case 1:
                    {
                        if (IsPosFree(_coordinates[1].x, _coordinates[1].y + 2) == 0 & IsPosFree(_coordinates[2].x + 1, _coordinates[2].y + 1) == 0 & IsPosFree(_coordinates[4].x - 1, _coordinates[4].y - 1) == 0)
                        {
                            for (int i = 0; i <= _coordinates.Count - 1; i++)
                            {
                                _lastcoordinates[i].x = _coordinates[i].x;
                                _lastcoordinates[i].y = _coordinates[i].y;
                            }
                            _coordinates[1].y = _coordinates[4].y + 2;
                            _coordinates[2].x++;
                            _coordinates[2].y++;
                            _coordinates[4].x--;
                            _coordinates[4].y--;
                            Pos = 2;
                        }
                        break;
                    }
                case 2:
                    {
                        if (IsPosFree(_coordinates[1].x+2, _coordinates[1].y) == 0 & IsPosFree(_coordinates[2].x + 1, _coordinates[2].y - 1) == 0 & IsPosFree(_coordinates[4].x - 1, _coordinates[4].y + 1) == 0)
                        {
                            for (int i = 0; i <= _coordinates.Count - 1; i++)
                            {
                                _lastcoordinates[i].x = _coordinates[i].x;
                                _lastcoordinates[i].y = _coordinates[i].y;
                            }
                            _coordinates[1].x = _coordinates[4].x + 2;
                            _coordinates[2].x++;
                            _coordinates[2].y--;
                            _coordinates[4].x--;
                            _coordinates[4].y++;
                            Pos = 3;
                        }
                        break;
                    }
                case 3:
                    {
                        if (IsPosFree(_coordinates[1].x, _coordinates[1].y-2) == 0 & IsPosFree(_coordinates[2].x - 1, _coordinates[2].y - 1) == 0 & IsPosFree(_coordinates[4].x + 1, _coordinates[4].y + 1) == 0)
                        {
                            for (int i = 0; i <= _coordinates.Count - 1; i++)
                            {
                                _lastcoordinates[i].x = _coordinates[i].x;
                                _lastcoordinates[i].y = _coordinates[i].y;
                            }
                            _coordinates[1].y = _coordinates[4].y - 2;
                            _coordinates[2].x--;
                            _coordinates[2].y--;
                            _coordinates[4].x++;
                            _coordinates[4].y++;
                            Pos = 0;
                        }
                        break;
                    }
            }
        }
    }
}
